home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / fbuf / asserts.pas next >
Pascal/Delphi Source File  |  1996-04-08  |  2KB  |  64 lines

  1. unit Asserts;
  2. {
  3.    Project "Opnek Standard Library (Delphi)"                                   
  4.    Opnek Research                                                              
  5.    Copyright ⌐ 1995. All Rights Reserved.                                      
  6.                                                                                
  7.    SUBSYSTEM:     General Debug Assistance Library
  8.    FILE:          Assert.pas
  9.    AUTHOR:        Jay Cole
  10.    WRITTEN:       03/04/1995
  11.    LAST ASSERT:   36
  12.  
  13.  
  14.    OVERVIEW
  15.    ========
  16.    Because C/C++ allows #defines, it is much easier to implement a non
  17.    intrusive assert().  here, we can copy the assert code, but the procedure
  18.    call still happens.  So, we should at the outer level also ifdef out the
  19.    actual call to assert.  usually this can be accomplished by calling assert
  20.    just like normal, and then search for asserts() after you finish with reg
  21.    expressions and put the conditionals at the beginning and end.
  22.    You must create a (DEFINE of _NDEBUG) to avoid calling the debug procedures
  23.    that are thrown.
  24.  
  25.    UPDATE HISTORY
  26.    ==============
  27.    03/04/95 (JLC) - Created
  28. }
  29.  
  30. interface
  31.  
  32. { Call if you need to verify implied conditions }
  33. procedure Assert(cond : boolean; const msgStr : string; ndx : integer);
  34.  
  35. implementation
  36. {$ifdef WINDOWS}
  37.    uses WinProcs, SysUtils, WinTypes;
  38. {$else}
  39.    uses sysUtils;
  40. {$endif}
  41.  
  42. { Called when a procedure assumption is not met }
  43. procedure Assert(cond : boolean; const msgStr : string; ndx : integer);
  44. var msgOut : array[0..255] of char;
  45.     msgNum : array[0..20] of char;
  46.     tstr : string;
  47. begin
  48.    {$ifndef _NDEBUG}
  49.       if (not cond) then begin
  50.          StrPCopy(msgOut, msgStr);
  51.          Str(ndx, msgNum);
  52.          StrCat(msgOut, '('); StrCat(msgOut, msgNum); StrCat(msgOut, ')');
  53.          {$ifdef WINDOWS}
  54.             MessageBox(0, 'Assert Failed', msgOut, MB_OK);
  55.          {$else}
  56.             Write('Assert Failed', msgOut);
  57.          {$endif}
  58.          halt;
  59.       end;
  60.    {$endif}
  61. end;
  62.  
  63. end.
  64.